<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>查询学生信息</title>
    <link rel="stylesheet" type="text/css" href="/app/Public/layui/css/layui.css">
    <script src="/app/Public/layui/layui.js"></script>
</head>
<h1 align="center" >查询学生信息</h1>
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>学生成绩查询</legend>
</fieldset>

<form name="form" method="post" class="layui-form" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">姓名</label>
        <div class="layui-input-block">
            <input type="text" id="name" name="name" lay-verify="title" autocomplete="off" placeholder="请输入姓名" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">系别</label>
        <div class="layui-input-block">
            <input type="text" id="department" name="department" lay-verify="title" autocomplete="off" placeholder="请输入系别" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">学科</label>
        <div class="layui-input-block">
            <input type="text" id="subject" name="subject" lay-verify="title" autocomplete="off" placeholder="请输入学科" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">分数</label>
        <div class="layui-input-block">
            <input type="text" id="score" name="score" lay-verify="title" autocomplete="off" placeholder="请输入分数" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">时间</label>
        <div class="layui-input-block">
            <input type="text" id="time" name="time" lay-verify="title" autocomplete="off" placeholder="请输入时间" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <input id="check_btn" name="submit" type="button" value="查询"  class="layui-btn" >
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>




<table class="layui-table">
    <tr >
        <th>id</th>
        <th>姓名</th>
        <th>系别</th>
        <th>学科</th>
        <th>分数</th>
        <th>时间</th>
        <th>    </th>
    </tr>
    <tbody class="list_box">
    <tr>

    </tr>

    </tbody>

</table>

<a href="main.html" class="layui-btn layui-btn-danger">返回首页</a>

<script src="/app/Public/js/jquery-2.1.1.min.js"></script>
<script type="text/javascript">

    layui.use([  'layer', 'table'], function(){
        var layer = layui.layer //弹层
            ,table = layui.table ;//表格



        $(function () {
            $("#check_btn").click(function () {
                var param = {
                    // id:$("#id").val(),
                    name: $("#name").val(),
                    department: $("#department").val(),
                    subject: $("#subject").val(),
                    score: $("#score").val(),
                    time: $("#time").val(),
                };
                $.ajax({
                    url: '/app/index.php/Student/Text/find2',
                    type: "POST",
                    dataType: "JSON",
                    data: param,
                    //data是发送到服务器的数据
                    success: function (data) {
                        var box = $('.list_box').empty();

                        console.log(data);
                        $.each(data, function (k, v) {
                            box.append(
                                '<tr data-id="' + v.id + '">' +
                                '<td >' + v.id + '</td>' +
                                '<td>' + v.name + '</td>' +
                                '<td>' + v.department + '</td>' +
                                '<td>' + v.subject + '</td>' +
                                '<td>' + v.score + '</td>' +
                                '<td>' + v.time + '</td>' +
                                '<td>' + '<input class="del_btn"  type="button" value="删除" data-id="' + v.id + '" >' + '</td>' +
                                '</tr>'
                            );

                        });

                        // 监听class=del_btn的元素，点击时触发,写在这是因为按钮节点是动态生成的
                        $('.del_btn').click(function () {
                            removeTr($(this).attr('data-id'));
                        });
                    },
                    error: function () {
                        alert("提交失败！");
                    }
                });
            });

        });
        //
        // layer.confirm('是否删除该数据？', {
        //     btn: ['删除','取消'] //按钮
        // }, function(){
        //     layer.msg('删除成功', {icon: 1});
        // }, function(){
        //     layer.msg('也可以这样', {
        //         time: 20000, //20s后自动关闭
        //         btn: ['明白了', '知道了']
        //     });
        // });




        function removeTr(id) {
            if (confirm('是否删除该数据?')) {
                $.ajax({
                    url: '/app/index.php/Student/Text/del',
                    type: "POST",
                    dataType: "JSON",
                    data: {id: id},
                    success: function (data) {
                        if (data.code == 0) {
                            layer.msg(data.msg);
                            $("tr[data-id=" + id + "]").remove();

                        } else {
                            layer.msg(data.msg);
                        }


                    }
                })
            }

        }

    })

</script>


</body>
</html>